<!DOCTYPE html>
<html lang='zh-CN'>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>任务管理</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
<link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid p-t-15">

  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-header">

          <div id="toolbar" class="toolbar-btn-action">
              <form class="form-inline" method="post" id="searchForm">
                <div class="form-group">
                  <label>任务名称:</label>
                  <input type="text" class="form-control" name="jobName">
                </div>
                <div class="form-group">
                  <label>任务分组:</label>
                  <select name="logType" class="form-control">
                    <option value="">全部</option>
                    <option value="DEFAULT">默认</option>
                    <option value="SYSTEM">系统</option>
                  </select>
                </div>
                <div class="form-group">
                  <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-success btn_query btn-round" type="button" id="addBtn">添加</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-danger btn_query btn-round" type="button" id="deleteBtn">删除</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-primary btn_query btn-round" type="button" id="watchBtn">日志</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-warning btn_query btn-round" type="button" onclick="changeQuartzStatus(1)">暂停</button>
                </div>
                <div class="form-group">
                  <button class="btn btn-success btn_query btn-round" type="button" onclick="changeQuartzStatus(0)">启用</button>
                </div>
              </form>
          </div>

        </div>
        <div class="card-body table-responsive">

          <table id="data_grid"></table>

        </div>
      </div>
    </div>
  </div>

  <!--  添加与编辑模态框 -->
  <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="exampleModalLabel">任务管理</h4>
        </div>
        <div class="modal-body">
          <form id="addOrEditForm" method="post">
            <div class="row">
              <div class="col-xs-12">
                <div class="input-group m-b-10">
                  <span class="input-group-addon">任务名称</span>
                  <input type="hidden" name="jobId">
                  <input type="text" name="jobName" class="form-control">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="input-group m-b-10">
                  <span class="input-group-addon">任务分组</span>
                  <select name="jobGroup" class="form-control">
                    <option value="DEFAULT">默认</option>
                    <option value="SYSTEM">系统</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="input-group m-b-10">
                  <span class="input-group-addon">调用目标字符串</span>
                  <input type="text" name="invokeTarget" class="form-control">
                  <li>Bean调用示例：ryTask.ryParams('ry')</li>
                  <li>Class类调用示例：com.ruoyi.quartz.task.RyTask.ryParams('ry')</li>
                  <li>参数说明：支持字符串，布尔类型，长整型，浮点型，整型</li>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="input-group m-b-10">
                  <span class="input-group-addon">cron表达式</span>
                  <input type="text" name="cronExpression" class="form-control">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="example-box">
                  <label>执行策略</label> &nbsp;&nbsp;&nbsp;
                  <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="misfirePolicy" value="1"><span>立即执行</span>
                  </label>
                  <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="misfirePolicy" value="2"><span>执行一次</span>
                  </label>
                  <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="misfirePolicy" value="3"><span>放弃执行</span>
                  </label>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="example-box">
                  <label>并发执行</label> &nbsp;&nbsp;&nbsp;
                  <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="concurrent" value="0"><span>允许</span>
                  </label>
                  <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="concurrent" value="1"><span>禁止</span>
                  </label>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="example-box">
                  <label>任务状态</label> &nbsp;&nbsp;&nbsp;
                  <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="status" value="0"><span>正常</span>
                  </label>
                  <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="status" value="1"><span>暂停</span>
                  </label>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="input-group m-b-10">
                  <span class="input-group-addon">备注</span>
                  <textarea type="text" name="remark" class="form-control"></textarea>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button type="button" class="btn btn-primary" id="saveFormBtn">保存</button>
            </div>
          </form>
        </div>

      </div>
    </div>
  </div>


  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/bootstrap.min.js"></script>
  <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
  <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
  <!--行内编辑插件-->
  <link href="js/x-editable/1.5.1/bootstrap3-editable/css/bootstrap-editable.min.css" rel="stylesheet">
  <script type="text/javascript" src="js/x-editable/1.5.1/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
  <script type="text/javascript" src="js/bootstrap-table/extensions/editable/bootstrap-table-editable.min.js"></script>
  <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
  <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
  <!-- jquery-form表单提交插件 -->
  <script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
  <!-- bootstrap弹出框插件 -->
  <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
  <!-- 表单填充插件 -->
  <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>

  <script type="text/javascript">

      //设置表头
      var columns = [
          {checkbox: true},
          {field: 'jobId',title: 'ID'},
          {field: 'jobName',title: '任务名称'},
          {field: 'jobGroup',title: '任务组名'},
          {field: 'invokeTarget',title: '调用目标字符串', class: "text-success"},
          {field: 'cronExpression',title: 'cron执行表达式'},
          {field: 'misfirePolicy',title: '计划执行错误策略', visible: false},
          {field: 'concurrent',align:'center',title: '是否并发执行', formatter: function(value) {
             return value == 0 ? '<span class="label label-success">允许</span>':'<span class="label label-danger">禁止</span>';
          }},
          {
              field: 'status',
              title: '状态',
              pk: 1,
              editable: {
                  type: 'select',
                  title: "状态",
                  source: [
                      { value: 0, text: '正常'},
                      { value: 1, text: '暂停'}
                  ],
                  noeditFormatter: function (value) {
                      return value == 1 ? { filed: "status", value: "禁用", class: "label label-warning" } : { filed: "status", value: "正常", class: "label label-success" }; // 这里对bootstrap-table-editable.min.js做了一些修改，让其能接收class
                  }// 可以按列分开做保存，也可以用后面的onEditableSave
              }
          },
          {field: 'create_time',title: '创建时间', formatter: function (value) {
                  return zero2one.dateFormat(value, 'Y-m-d H:i:s')
           }}
      ];

      //进入主界面加载数据
      zero2one.datagrid("data_grid", "/quartzPage?f="+new Date().getTime(),function (params) {
          return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
      }, columns);

      //点击查询按钮重新加载页面数据
      $("#searchFormBtn").click(function () {
          $('#data_grid').bootstrapTable('refresh');
      });

      //点击添加按钮弹出模态框
      $("#addBtn").click(function () {
          $("#addOrEditForm")[0].reset();
          $("#addOrEditModal").modal("show");
      });

      //点击编辑按钮弹出模态框
      $("#editBtn").click(function () {
          //获取选中行的数据
          var datas = $('#data_grid').bootstrapTable('getSelections');
          //判断是否选中行数据，如果没有则提示
          if(datas.length == 1){
              //填充表单
              $("#addOrEditForm").formloader({data: datas[0]});
          }else{
              $.messager.alert("温馨提示", "请选择一条数据操作");
              return;
          }
          $("#addOrEditModal").modal("show");
      });

      $("#saveFormBtn").click(function () {
            zero2one.request("/addOrEditQuartz?f="+new Date().getTime(),$("#addOrEditForm").serialize(),function (data) {
                zero2one.success(data);
            });
      });

      zero2one.girdClick("data_grid");

      //改变用户状态
      function changeQuartzStatus(status) {
          //获取选中行的数据
          var datas = $('#data_grid').bootstrapTable('getSelections');
          //判断是否选中行数据，如果没有则提示
          if(datas.length == 1){
              $.messager.confirm("温馨提示", "您确定要更改任务状态吗?", function () {
                  datas[0].status = status;
                  zero2one.request("/changeQuartzStatus?f="+new Date().getTime(),datas[0],function (data) {
                      zero2one.success(data);
                  });
              })
          }else{
              $.messager.alert("温馨提示", "请选择一条数据操作");

          }
      }

      $("#deleteBtn").click(function () {
          //获取选中行的数据
          var datas = $('#data_grid').bootstrapTable('getSelections');
          //判断是否选中行数据，如果没有则提示
          if(datas.length == 1){
              $.messager.confirm("温馨提示", "您确定要删除任务吗?", function () {
                  zero2one.request("/delQuartz?f="+new Date().getTime(),datas[0],function (data) {
                      zero2one.success(data);
                  });
              })
          }else{
              $.messager.alert("温馨提示", "请选择一条数据操作");

          }
      });

      $("#watchBtn").click(function () {
          zero2one.tab("日志详情","/quartzLogList.html",36);
      });

  </script>

</div>
</body>
</html>